<?php 
	class halaman_member extends CI_model{

		function get_wisata($id_language, $limit, $offset){
			$q = $this->db->query("SELECT w.id_wisata, w.id_kategori_sub, wl.alamat_wisata, wl.fasilitas_wisata, wl.kontak_wisata, wl.harga_tiket_wisata, w.id_member, w.id_kota, w.id_provinsi, w.latitude_wisata, w.longitude_wisata, ksl.nama_kategori_sub, w.url_gambar_wisata, wl.judul_wisata, wl.content_wisata, DATE_FORMAT(w.date_update,'%d %b %Y') as 'date_update' 
								   FROM
								   setting s
								   JOIN
								   kategori_sub ks ON s.id_table=ks.id_kategori
								   JOIN
								   kategori_sub_language ksl ON ks.id_kategori_sub=ksl.id_kategori_sub
								   JOIN
								   wisata w ON ks.id_kategori_sub=w.id_kategori_sub
								   JOIN
								   wisata_language wl ON w.id_wisata=wl.id_wisata
								   WHERE
								   s.key='portofolio' AND wl.id_language=$id_language
								   ORDER BY w.id_wisata DESC LIMIT $offset, $limit");

			return $q->result();
		}

		function get_wisata_view($id_language, $id){
			$q = $this->db->query("SELECT w.id_wisata, kb.id_kota, kb.kota_kabupaten, kb.id_provinsi, w.id_provinsi, w.id_kategori_sub, wl.alamat_wisata, wl.fasilitas_wisata, wl.kontak_wisata, wl.harga_tiket_wisata, w.id_member, w.id_kota, w.latitude_wisata, w.longitude_wisata, ksl.nama_kategori_sub, w.url_gambar_wisata, wl.judul_wisata, wl.content_wisata,p.provinsi, DATE_FORMAT(w.date_update,'%d %b %Y') AS 'date_update' 
								   FROM
								   setting s
								   JOIN
								   kategori_sub ks ON s.id_table=ks.id_kategori
								   JOIN
								   kategori_sub_language ksl ON ks.id_kategori_sub=ksl.id_kategori_sub
								   JOIN
								   wisata w ON ks.id_kategori_sub=w.id_kategori_sub
								   JOIN
								   kota_kabupaten kb ON w.id_kota=kb.id_kota AND w.id_provinsi=kb.id_provinsi
								   JOIN
								   provinsi p ON w.id_provinsi=p.id_provinsi
								   JOIN
								   wisata_language wl ON w.id_wisata=wl.id_wisata
								   WHERE
								   s.key='portofolio' AND wl.id_language=$id_language
								   AND w.id_wisata=$id GROUP BY w.id_wisata");

			return $q->result();
		}

		function get_wisata_rows($id_language){
			$q = $this->db->query("SELECT * 
								   FROM
								   setting s
								   JOIN
								   kategori_sub ks ON s.id_table=ks.id_kategori
								   JOIN
								   kategori_sub_language ksl ON ks.id_kategori_sub=ksl.id_kategori_sub
								   JOIN
								   wisata w ON ks.id_kategori_sub=w.id_kategori_sub
								   JOIN
								   wisata_language wl ON w.id_wisata=wl.id_wisata
								   WHERE
								   s.key='portofolio' AND wl.id_language=$id_language");

			return $q->num_rows();
		}

		function get_comment($id){
			$q = $this->db->query("SELECT *,DATE_FORMAT(date_update,'%d %b %Y') as 'date_comment'
								   FROM
								   comment
								   WHERE status = 1 AND
								   id_wisata=$id ORDER BY date_update DESC");

			return $q->result();
		}

		function get_comment_row($id){
			$q = $this->db->query("SELECT *
								   FROM
								   comment
								   WHERE status = 1 AND
								   id_wisata=$id");

			return $q->num_rows();
		}

		function get_foto_slide($id){
			$q = $this->db->query("SELECT *
								   FROM
								   wisata_foto
								   WHERE id_wisata=$id");

			return $q->result();
		}

		function get_rating($id){
			$q = $this->db->query("SELECT avg(total_votes) rate
								   FROM
								   ratings
								   WHERE total_value = $id");
			$d = $q->row();

			return $d->rate;
		}

	}

?>